//
//  ListSecondTableViewCell.m
//  项目A --半糖
//
//  Created by romana on 16/6/6.
//  Copyright © 2016年 romana. All rights reserved.
//

#import "ListSecondTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "NewThirdDetailsViewController.h"

@implementation ListSecondTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self doSomething];
    }
    
    return  self;
    
    
}


-(void)doSomething{
    
    self.TopGapView = [[UIView alloc] init];
    self.TopGapView.backgroundColor = [UIColor colorWithRed:220 / 255.0 green:220 / 255.0 blue:220 / 255.0 alpha:0.8];
    [self.contentView addSubview:self.TopGapView];
    
    self.bottomGapView = [[UIView alloc] init];
    self.bottomGapView.backgroundColor = [UIColor colorWithRed:220 / 255.0 green:220 / 255.0 blue:220 / 255.0 alpha:0.8];
    [self.contentView addSubview:self.bottomGapView];
    
    self.smallTitleImageV = [[UIImageView alloc] init];
    self.smallTitleImageV.backgroundColor = [UIColor whiteColor];
    self.smallTitleImageV.image = [UIImage imageNamed:@"flag"];
    [self.contentView addSubview:self.smallTitleImageV];
    
    self.titleLabel = [[UILabel alloc] init];
    self.titleLabel.font = [UIFont systemFontOfSize:22];
    self.titleLabel.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.titleLabel];
    
    self.bigTextLabel = [[UILabel alloc] init];
    //换行时一起用
    self.bigTextLabel.numberOfLines = 0;
    self.bigTextLabel.lineBreakMode = NSLineBreakByCharWrapping;
    self.bigTextLabel.backgroundColor = [UIColor whiteColor];
    
    [self.contentView addSubview:self.bigTextLabel];
    
    self.priceLabel = [[UILabel alloc] init];
    self.priceLabel.textAlignment = NSTextAlignmentCenter;
    self.priceLabel.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.priceLabel];
    
    self.likesLabel = [[UILabel alloc] init];
    self.likesLabel.backgroundColor = [UIColor whiteColor];
    self.likesLabel.textAlignment = NSTextAlignmentCenter;
    
    [self.contentView addSubview:self.likesLabel];
    
    self.heartImageV = [[UIImageView alloc] init];
    self.heartImageV.backgroundColor = [UIColor whiteColor];
    self.heartImageV.image = [UIImage imageNamed:@"heart"];
    [self.likesLabel addSubview:self.heartImageV];
    
    self.buyButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.buyButton.backgroundColor = [UIColor cyanColor];
    self.buyButton.alpha = 0.8;
    [self.buyButton setTitle:@"购买" forState:UIControlStateNormal];
    self.buyButton.layer.masksToBounds = YES;
    self.buyButton.layer.cornerRadius = 10;
    [self.buyButton addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.buyButton];
    
    self.bottomGapView = [[UIView alloc] init];
    self.bottomGapView.backgroundColor = [UIColor colorWithRed:220 / 255.0 green:220 / 255.0 blue:220 / 255.0 alpha:0.8];
    
    [self.contentView addSubview:self.bottomGapView];
 
    
    
}

-(void)layoutSubviews{
    
    
    self.TopGapView.frame = CGRectMake(0, 0, self.frame.size.width, 5);
    self.smallTitleImageV.frame = CGRectMake(5, 25, 22, 22);
    self.titleLabel.frame = CGRectMake(30, 10, self.frame.size.width - 40, 50);
    
    self.bigTextLabel.frame = CGRectMake(10, 60 , self.frame.size.width - 20, 150);
    
    self.priceLabel.frame = CGRectMake(0, self.myImageArray.count * 360 + 300, self.frame.size.width / 3, 50);
    
    self.likesLabel.frame = CGRectMake(self.frame.size.width / 3, self.myImageArray.count * 360 + 300, self.frame.size.width / 3, 50);
    self.heartImageV.frame = CGRectMake(25, 15, 20, 20);
    self.buyButton.frame = CGRectMake(self.frame.size.width / 3 * 2, self.myImageArray.count * 360 + 300, self.frame.size.width / 3, 50);
    self.bottomGapView.frame = CGRectMake(0, self.myImageArray.count * 360 + 350, self.frame.size.width, 5);
    
}





-(void)setNDSModel:(NewDetailsSecondModel *)NDSModel{
    
    _NDSModel = NDSModel;
    
    self.titleLabel.text = _NDSModel.title;
    self.bigTextLabel.text = _NDSModel.desc;
    NSString *string = [NSString stringWithFormat:@"参考价: ¥%@",_NDSModel.price];
    self.priceLabel.text = string;
    self.likesLabel.text = _NDSModel.likes;
    
    //for循环建立大图
    self.myImageArray = [NSMutableArray array];
    self.myImageArray = [NSMutableArray arrayWithArray:_NDSModel.PicArray];
    
    
    // NSLog(@"%ld", self.contentView.subviews.count);
    
    for (int i = 0; i < self.myImageArray.count; i++) {
        UIImageView *ImageV = [[UIImageView alloc] init];
        ImageV.backgroundColor = [UIColor cyanColor];
        ImageV.frame = CGRectMake(10, 220 + (i * 360), self.frame.size.width - 20, 350);
        
        NewDetailsPicModel *model = self.myImageArray[i];
        
        NSString *string1 = [NSString stringWithFormat:@"http://bt.img.17gwx.com/%@",model.picURL];
        //        ImageV.image = [UIImage ima];
        // NSString *string = @"http://bt.img.17gwx.com/";
        // string = [string stringByAppendingString:model.picURL];
        [ImageV sd_setImageWithURL:[NSURL URLWithString:string1] placeholderImage:[UIImage imageNamed:@"timg.jpeg"]];
        
        [self.contentView addSubview:ImageV];
        
        
        //        [self.contentView addSubview:ImageV];
        
    }
    
    //for循环加头像
    self.myHeadArray = [NSMutableArray array];
    self.myHeadArray = [NSMutableArray arrayWithArray:_NDSModel.LikeListArray];
    for (int i = 0; i < self.myHeadArray.count; i++) {
        UIImageView *ImageV = [[UIImageView alloc] init];
        ImageV.layer.masksToBounds = YES;
        ImageV.layer.cornerRadius = 15;
        ImageV.backgroundColor = [UIColor cyanColor];
        ImageV.frame = CGRectMake(10 + (i * 40), 220 + (self.myImageArray.count * 360) + 30, 30, 30);
        NewDetailsLikeListModel *model = self.myHeadArray[i];
        NSString *string = [NSString stringWithFormat:@"http://7te7t9.com2.z0.glb.qiniucdn.com/%@",model.picURL] ;
        
        ImageV.image = [UIImage imageNamed:@"timg.jpeg"];
        
        [ImageV sd_setImageWithURL:[NSURL URLWithString:string] placeholderImage:[UIImage imageNamed:@"timg.jpeg"]];
        [self.contentView addSubview:ImageV];
        
    }
    
    
}

-(void)buttonAction{
    
    //    NewThirdDetailsViewController *NTDVC = [[NewThirdDetailsViewController alloc] init];
    //    NTDVC.url = self.NDSModel.url;
    
    NSLog(@"1111");
    
    self.myBlock();
    
    
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
